package com.minisoft.jd.seckill;

import cn.hutool.core.io.FileUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author JueSu
 * @description: TODO
 * @date 2021/11/29 16:57
 */
public class Test {
    @org.junit.Test
    public void cpCookie() {

        String body = HttpUtil.get("https://item-soa.jd.com/getWareBusiness?skuId=100015280610");

        File f = new File("jue.png");

        boolean isFile = FileUtil.isFile("jue.png");

        String orderCookieStr = "__jdv=122270672|direct|-|none|-|1638531655946; __jdc=122270672; __jda=122270672.1638531655945303125104.1638531656.1638531656.1638531656.1; __jdu=1638531655945303125104; shshshfp=753409dfebcdeeb0790ed8790389066f; shshshfpa=cf732116-caf0-97fd-c2f0-1aca0761adec-1638531657; shshshfpb=ycQHl0hdWhba/u4srY4QPoA; TARGET_UNIT=bjcenter; ipLoc-djd=19-1657-0-0; areaId=19; wlfstk_smdl=poo8lkgz9wlpi5vbg1osroys1uk596oy; 3AB9D23F7A4B3C9B=Q4FVL6B2VHDD62QTWWOZ6LIXXI2PZAGG2EOO65ZHN72ORHCYBN2Q2BF7DQMB6XMLPMLEYAL7MPRWGFUOVL3LBWM66I; TrackID=1W0D_6xO-PFdOu43DzJuoEl9PcF__hhj3TzGJDjP-GV-YInfsLuupF7nXUHzeSZ_OHOc9-tOmor04_AuK3v0wVHWoJXsh3pT8d8Y3-_8c7WUoKN696BmcNGQDatlo91-k; thor=F6F23D181456979A3C63356AED1ADB78DED80DD2F5BC9CF093978DF59E5942EF23BBC43BE1E5D8BF148306B3CCB1420DDF692607FDBFD2A18C8D82B2A1C74B06ABCE5DED3DCEB9A13978A91D1E6AB16D56615F1B14242702A06AC7219E11D6F5931FF6CBE075558CFF9DE2C7F8C642FC8B80BBEACDC3ECEC83E6598EB8B989C49930251E0A859C9902286C1A5157A69FC2036FF679C982E425E013C707D2934E; pinId=KrFFgqEgdSwpr-s28BTiObV9-x-f3wj7; pin=jd_6a9270ede4cb8; unick=jd_135909bssq; ceshi3.com=201; _tp=f0kpbB1FWHAY2oToBgv9Hu1GtTgGBEstZ2rqP6IWsdc%3D; _pst=jd_6a9270ede4cb8; cn=156; __jdb=122270672.5.1638531655945303125104|1.1638531656; shshshsID=11d0b1aebc78da2d91e51c3cb434f2c6_2_1638531676660";
        String oldCookieStr = "__jdc=122270672; __jda=122270672.16385315732231875663622.1638531573.1638531573.1638531573.1; __jdv=122270672|direct|-|none|-|1638531573224; __jdu=16385315732231875663622; shshshfp=753409dfebcdeeb0790ed8790389066f; shshshfpa=00494d8e-3dd9-67db-beb6-07a71aa20a73-1638531574; shshshfpb=yPV4CACQOe+vXN0I23T5Z3g; TARGET_UNIT=bjcenter; ipLoc-djd=19-1657-0-0; areaId=19; wlfstk_smdl=cfzh4ep86pj9zgtgn02agtm988vkxo3a; 3AB9D23F7A4B3C9B=Q4FVL6B2VHDD62QTWWOZ6LIXXI2PZAGG2EOO65ZHN72ORHCYBN2Q2BF7DQMB6XMLPMLEYAL7MPRWGFUOVL3LBWM66I; TrackID=1IKVreVAqNeV37t0ek4dpzg3rBFFvOHlogBz8_nOvisMckfUSdnaBs170ZbJp_j21eOXg9wpCL-oQSMAj0M_tuEeSxGQMu8fvg8SIdcDNEs4; thor=A6B163847E03FD546F3BF4599CDE88FE61FDC016C3048A4C8FA3BD124FD7126979A9BC7126960A106BCCCD370EAA5D8471CA57B203DFF7B5BD52DB252081292803172D2892B84D4B129447BBA2121499B651E9628D72C177E221CA444A047D1650F07B43626BE86431F8E5385C59A5481767155E53BC933B29B33C97766C1193992CEA039E21BC2CD3090DCA5D347E8F; pinId=EvE-50nGwH3ZTlS-EiSWPA; pin=juesuchen; unick=%E5%8D%97%E5%B8%8Cnancy%E6%BD%98; ceshi3.com=103; _tp=uJs1qGio5uDIOiZ1tFsPbw%3D%3D; _pst=juesuchen; cn=52; __jdb=122270672.5.16385315732231875663622|1.1638531573; shshshsID=8eab52ed44da525819318f35405b43c3_2_1638531591933";
        String[] split = orderCookieStr.split("; ");
        String[] oldSplit = oldCookieStr.split("; ");

        for (String s : split) {
            System.out.println(s);
        }

        System.out.println("=======");
        for (String s : oldSplit) {
            System.out.println(s);
        }

    }

    @org.junit.Test
    public void testIsPlusMember() {
        List<String> headers = FileUtil.readUtf8Lines("D:\\temp\\jd\\bake\\header.txt");
        Map<String,String> headMap = new HashMap<>();
        Map<String, String> headerMap = Killer.getHeaderMap(1);
        headers.forEach(item -> {
            String[] split = item.split(": ");
            headMap.put(split[0],split[1]);
            if (split[0].equals("Cookie")) {
                headerMap.put(split[0],split[1]);
            }
        });

        headerMap.put("Host","order.jd.com");
        String body = HttpUtil.createPost("https://order.jd.com/lazy/isPlusMember.action").headerMap(headerMap, true).execute().body();
        System.out.println(body);
        System.out.println(headerMap);
    }
}
